package com.example.demo.service;

import com.example.demo.entity.LikeNoteComment;
import com.example.demo.entity.NoteCollection;
import com.example.demo.mapper.NoteCollectionMapper;
import com.example.demo.vo.ViewNoteCollectionInfo;
import com.example.demo.vo.ViewNoteCreateInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteCollectionImpl implements NoteCollectionService {

    @Autowired
    private NoteCollectionMapper noteCollectionMapper;

    //根据用户ID查找对应用户喜欢的笔记
    @Override
    public PageInfo<ViewNoteCollectionInfo> findNoteCollectionInfo(Integer user_id) {
        List<ViewNoteCollectionInfo> list = noteCollectionMapper.findNoteCollectionInfoId(user_id);
        PageInfo<ViewNoteCollectionInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //取消收藏
    @Override
    public Integer deleteNoteCollection(Integer collection_id){
        return noteCollectionMapper.deleteNoteCollection(collection_id);
    }

    //根据用户id计数
    @Override
    public Integer countcollection( Integer user_id) {
        return noteCollectionMapper.countcollection(user_id);
    }

    //根据笔记id计数
    @Override
    public Integer countcollectionnoteid( Integer note_create_id) {
        return noteCollectionMapper.countcollectionnoteid(note_create_id);
    }

    //根据用户id和笔记id，收藏笔记。
    @Override
    public boolean insertNoteCollection(NoteCollection noteCollection) {
        return noteCollectionMapper.insertNoteCollection(noteCollection) > 0;

    }

    //取消收藏，笔记详情页
    @Override
    public boolean deleteNoteCollection1(NoteCollection noteCollection) {
        return noteCollectionMapper.deleteNoteCollection1(noteCollection.getUser_id(), noteCollection.getNote_create_id()) > 0;
    }

    //查询是否已经收藏过
    @Override
    public boolean checkIfNoteCollection(Integer user_id, Integer note_create_id) {
        return noteCollectionMapper.checkIfNoteCollection(user_id, note_create_id) > 0;
    }

}
